using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

public class LoaiSanPhamDAO : AbstractDAO
{
    public LoaiSanPhamDAO(String strPath)
        : base(strPath)
    {

    }
    ~LoaiSanPhamDAO()
    {
        base.Dispose();
    }

    public DataSet SelectTenLoaiSanPham(int id)
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectTenLoaiSanPham";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            base.FillDataSet(ref ds, "SelectTenLoaiSanPham");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public DataSet SelectLoaiSanPhamAll()
    {
        DataSet ds;
        try
        {
            ds = new DataSet();
            base.sql = "usp_SelectLoaiSanPhamAll";
            base.FillDataSet(ref ds, "SelectLoaiSanPhamAll");
            return ds;
        }
        catch (System.Exception e)
        {
            throw new Exception(e.Message, e.InnerException);
        }
        finally
        {
            base.CleanUpObject();
        }
    }

    public Boolean InsertLoaiSanPham(LoaiSanPhamDTO loaisp)
    {
        try
        {
            base.sql = "usp_InsertLoaiSanPham";
            base.InitializeCommand();

            base.AddParameter("@TenLoaiSanPham",
            SqlDbType.NVarChar, 50, loaisp.TenLoaiSP);

            base.AddParameter("@MoTa",
            SqlDbType.NVarChar, 300, loaisp.MoTa);

            base.AddParameter("@Visible",
            SqlDbType.Bit, 10, loaisp.Visible);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);

        }
    }

    public Boolean UpdateLoaiSanPham(LoaiSanPhamDTO loaisp)
    {
        try
        {
            base.sql = "usp_UpdateLoaiSanPham";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, loaisp.Id);

            base.AddParameter("@TenLoaiSanPham",
            SqlDbType.NVarChar, 100, loaisp.TenLoaiSP);

            base.AddParameter("@MoTa",
            SqlDbType.NVarChar, 1000, loaisp.MoTa);

            base.AddParameter("@Visible",
            SqlDbType.Bit, 10, loaisp.Visible);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            return false;

        }
    }

    public Boolean DeleteLoaiSanPham(int id)
    {
        try
        {
            base.sql = "usp_DeleteLoaiSanPham";
            base.InitializeCommand();

            base.AddParameter("@id",
            SqlDbType.Int, 10, id);

            return ExecuteStoredProcedure();
        }
        catch (System.Exception ExceptionErr)
        {
            throw new System.Exception(ExceptionErr.Message,
            ExceptionErr.InnerException);
        }
    }

}